package interview.huawei.training.p20;

import java.util.Scanner;

public class Main {
    // 判断密码长度
    public static boolean checkLength(String password) {
        if(password.length() <= 8) 
            return false;
        return true;
    }
    
    // 统计数字、大小写字母和其他字符的出现情况
    public static boolean checkCharKinds(String password) {
        int digit = 0, lowercase = 0, uppercase = 0, others = 0;
        for(int i = 0; i < password.length();i++) {
            char ch = password.charAt(i);
            if(ch >= '0' && ch <= '9') digit = 1;
            else if(ch >= 'a' && ch <= 'z') lowercase = 1;
            else if(ch >= 'A' && ch <= 'Z') uppercase = 1;
            else others = 1;
        }
        // 小于三种不合法
        if(digit + lowercase + uppercase + others < 3)
            return false;
        return true;
    }
    
    // 不能有相同长度超过2的子串重复
    /*public static boolean checkSubstrRepeat(String password) {
        for(int i = 0; i < password.length() - 2; i++)  {
            String substr = password.substring(i, i + 3);
            String substr2 = password.substring(i + 1);
            if(substr2.contains(substr))
                return false;
        }
        return true;
    }*/
    public static boolean checkSubstrRepeat(String password) {
        for(int i = 0; i < password.length() - 6; i++)  {
            String substr = password.substring(i, i + 3);
            String substr2 = password.substring(i + 3);
            if(substr2.contains(substr))
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()) {
            String password = scanner.nextLine();
            // 长度大于8，数字、大小写字母和其他字符至少三种
            if(checkLength(password) && checkCharKinds(password) && checkSubstrRepeat(password))
                System.out.println("OK");
            else
                System.out.println("NG");
        }
    }
}